<?php
// +----------------------------------------------------------------------
// | sfadmin - Suifeng Administration
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2020 http://suifeng.tech All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: suifeng <1787585212@qq.com>
// +----------------------------------------------------------------------

namespace app\wechat\model;

use suifeng\Model;

class Tag extends Model
{
    protected $name = 'wechat_tag';

    public function query_count($where_list)
    {
        $where_map = $this->_build_where_map($where_list);
        return $this->where($where_map)
            ->count();
    }

    public function query_list($where_list, $page_num, $page_size, $sort_field, $sort_order)
    {
        $where_map = $this->_build_where_map($where_list);
        return $this->where($where_map)
            ->page($page_num, $page_size)
            ->order($sort_field, $sort_order)
            ->select();
    }

    private function _build_where_map($where_list)
    {
        $where_array = array();

        foreach ($where_list as $field => $value) {
            if ($value) {
                if ($field == 'search_word') {
                    $where_array['name'] = array('like', $value);
                } else {
                    $where_array[$field] = $value;
                }
            }
        }

        return $where_array;
    }

    //$where['m_username|mnickname'] = array('like', "%{$keyword}%", 'or');
}
